Final Lab Report - Chaos Game, L-Systems and Hilbert Curves

Lucca Tanzillo dos Santos
April 30rd, 2025

Introduction

In this lab, I explore the visual evolution of a two-dimensional complex grid under iterative transformations of the form \( z_{i+1} = z_i^n - c \), where \( z \in \mathbb{C} \) and \( c \) is a constant (in this case, 0.5). The grid is initialized over a square region of the complex plane ranging from -1 to 1 in both real and imaginary axes. Through iterative application of the transformation, we analyze how the values evolve with varying powers \( n \) and iteration counts, visually represented through dynamic plotting of the real and imaginary parts. This approach offers a computational perspective on fractal formation and complex dynamical systems. In this lab, I've opted to use Wolfram Mathematica because of its symbolic engine and dynamic interactivity—particularly through functions like Manipulate, which allow adjustment of parameters in real time, making it exceptionally suited for mathematical experimentation and visualization. Moreover, Mathematica handles complex arithmetic and large data visualizations efficiently, providing a visually rich representation of results. As Stephen Wolfram (2002) highlights in A New Kind of Science, simple iterative processes can generate unexpectedly intricate behavior, a principle clearly observable in this lab’s fractal-based experiment (Wolfram, 2002).

1. Chaos Game

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.

1.1 Original Code Documented

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.


def hilbert_curve(step, parity, n):
    "Draw a Hilbert curve of order n with given turtle, step size, and parity."
    if n == 0:
        return  # base case: no more recursion
    left(90 * parity)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    forward(step)
    right(90 * parity)
    hilbert_curve(step, parity, n - 1)       # Draw smaller curve with same parity
    forward(step)
    hilbert_curve(step, parity, n - 1)       # Draw another with same parity
    right(90 * parity)     
    forward(step)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    left(90 * parity)
    
# Set up the variables
n = 3
step = 500 / (2 ** n)  # scale step so curve stays within bounds

initializeTurtle()
showturtle()

# Set up the turtle
face(90)
jump(200, 550)
color('red')

# Draw the Hilbert Curve

hilbert_curve(step, 1, n)

show()

The plot below shows the result of interactively transforming a complex grid after one iteration, with the number of iterations controlled dynamically using the Manipulate interface. This built-in Wolfram Mathematica feature allows users to adjust parameters in real time and immediately observe the effects on the visual structure of the grid. The interface makes mexploration of complex behaviors both intuitive and efficient, enabling deeper insight into how iterative transformations distort mand evolve spatial patterns. Wolfram Mathematica is ideal for this task due to its native support for complex arithmetic, mefficient array operations, and built-in interactivity through Manipulate, making it easy to explore and share mathematical behavior visually and intuitively.

Hilbert Curves from n = 1 tp n = 6
Hilbert Curves: Variations from n = 1 to n = 6.

1.2 Expanding the code

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.


def hilbert_curve(step, parity, n):
    "Draw a Hilbert curve of order n with given turtle, step size, and parity."
    if n == 0:
        return  # base case: no more recursion
    left(90 * parity)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    forward(step)
    right(90 * parity)
    hilbert_curve(step, parity, n - 1)       # Draw smaller curve with same parity
    forward(step)
    hilbert_curve(step, parity, n - 1)       # Draw another with same parity
    right(90 * parity)     
    forward(step)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    left(90 * parity)
    
# Set up the variables
n = 3
step = 500 / (2 ** n)  # scale step so curve stays within bounds

initializeTurtle()
showturtle()

# Set up the turtle
face(90)
jump(200, 550)
color('red')

# Draw the Hilbert Curve

hilbert_curve(step, 1, n)

show()

The plot below shows the result of interactively transforming a complex grid after one iteration, with the number of iterations controlled dynamically using the Manipulate interface. This built-in Wolfram Mathematica feature allows users to adjust parameters in real time and immediately observe the effects on the visual structure of the grid. The interface makes mexploration of complex behaviors both intuitive and efficient, enabling deeper insight into how iterative transformations distort mand evolve spatial patterns. Wolfram Mathematica is ideal for this task due to its native support for complex arithmetic, mefficient array operations, and built-in interactivity through Manipulate, making it easy to explore and share mathematical behavior visually and intuitively.

Hilbert Curves from n = 1 tp n = 6
Hilbert Curves: Variations from n = 1 to n = 6.

2. L-Systems

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.

2.1 Original Code Documented

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.


def hilbert_curve(step, parity, n):
    "Draw a Hilbert curve of order n with given turtle, step size, and parity."
    if n == 0:
        return  # base case: no more recursion
    left(90 * parity)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    forward(step)
    right(90 * parity)
    hilbert_curve(step, parity, n - 1)       # Draw smaller curve with same parity
    forward(step)
    hilbert_curve(step, parity, n - 1)       # Draw another with same parity
    right(90 * parity)     
    forward(step)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    left(90 * parity)
    
# Set up the variables
n = 3
step = 500 / (2 ** n)  # scale step so curve stays within bounds

initializeTurtle()
showturtle()

# Set up the turtle
face(90)
jump(200, 550)
color('red')

# Draw the Hilbert Curve

hilbert_curve(step, 1, n)

show()

The plot below shows the result of interactively transforming a complex grid after one iteration, with the number of iterations controlled dynamically using the Manipulate interface. This built-in Wolfram Mathematica feature allows users to adjust parameters in real time and immediately observe the effects on the visual structure of the grid. The interface makes mexploration of complex behaviors both intuitive and efficient, enabling deeper insight into how iterative transformations distort mand evolve spatial patterns. Wolfram Mathematica is ideal for this task due to its native support for complex arithmetic, mefficient array operations, and built-in interactivity through Manipulate, making it easy to explore and share mathematical behavior visually and intuitively.

Hilbert Curves from n = 1 tp n = 6
Hilbert Curves: Variations from n = 1 to n = 6.

2.2 Expanding the code

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.


def hilbert_curve(step, parity, n):
    "Draw a Hilbert curve of order n with given turtle, step size, and parity."
    if n == 0:
        return  # base case: no more recursion
    left(90 * parity)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    forward(step)
    right(90 * parity)
    hilbert_curve(step, parity, n - 1)       # Draw smaller curve with same parity
    forward(step)
    hilbert_curve(step, parity, n - 1)       # Draw another with same parity
    right(90 * parity)     
    forward(step)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    left(90 * parity)
    
# Set up the variables
n = 3
step = 500 / (2 ** n)  # scale step so curve stays within bounds

initializeTurtle()
showturtle()

# Set up the turtle
face(90)
jump(200, 550)
color('red')

# Draw the Hilbert Curve

hilbert_curve(step, 1, n)

show()

The plot below shows the result of interactively transforming a complex grid after one iteration, with the number of iterations controlled dynamically using the Manipulate interface. This built-in Wolfram Mathematica feature allows users to adjust parameters in real time and immediately observe the effects on the visual structure of the grid. The interface makes mexploration of complex behaviors both intuitive and efficient, enabling deeper insight into how iterative transformations distort mand evolve spatial patterns. Wolfram Mathematica is ideal for this task due to its native support for complex arithmetic, mefficient array operations, and built-in interactivity through Manipulate, making it easy to explore and share mathematical behavior visually and intuitively.

Hilbert Curves from n = 1 tp n = 6
Hilbert Curves: Variations from n = 1 to n = 6.

3. Hilbert Curves

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.

3.1 Original Code Documented

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.


def hilbert_curve(step, parity, n):
    "Draw a Hilbert curve of order n with given turtle, step size, and parity."
    if n == 0:
        return  # base case: no more recursion
    left(90 * parity)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    forward(step)
    right(90 * parity)
    hilbert_curve(step, parity, n - 1)       # Draw smaller curve with same parity
    forward(step)
    hilbert_curve(step, parity, n - 1)       # Draw another with same parity
    right(90 * parity)     
    forward(step)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    left(90 * parity)
    
# Set up the variables
n = 3
step = 500 / (2 ** n)  # scale step so curve stays within bounds

initializeTurtle()
showturtle()

# Set up the turtle
face(90)
jump(200, 550)
color('red')

# Draw the Hilbert Curve

hilbert_curve(step, 1, n)

show()

The plot below shows the result of interactively transforming a complex grid after one iteration, with the number of iterations controlled dynamically using the Manipulate interface. This built-in Wolfram Mathematica feature allows users to adjust parameters in real time and immediately observe the effects on the visual structure of the grid. The interface makes mexploration of complex behaviors both intuitive and efficient, enabling deeper insight into how iterative transformations distort mand evolve spatial patterns. Wolfram Mathematica is ideal for this task due to its native support for complex arithmetic, mefficient array operations, and built-in interactivity through Manipulate, making it easy to explore and share mathematical behavior visually and intuitively.

Hilbert Curves from n = 1 tp n = 6
Hilbert Curves: Variations from n = 1 to n = 6.

3.2 Expanding the code

The code below deploys an interactive visualization to the Wolfram Cloud, where a grid of complex numbers is iteratively transformed and plotted based on a user-defined iteration count. The result is a dynamic display of evolving patterns in the complex plane. It uses several key functions: CloudDeploy publishes the content online, Manipulate enables real-time user interaction, and Module contains local variables to structure the computation. Subdivide generates evenly spaced values to define the grid, Outer[Complex, x, y] builds complex coordinates, and Flatten reshapes the grid into a list. A Do loop applies the transformation iteratively, and ListPlot renders the results, with labels and styling handled by Row and various plot options.


def hilbert_curve(step, parity, n):
    "Draw a Hilbert curve of order n with given turtle, step size, and parity."
    if n == 0:
        return  # base case: no more recursion
    left(90 * parity)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    forward(step)
    right(90 * parity)
    hilbert_curve(step, parity, n - 1)       # Draw smaller curve with same parity
    forward(step)
    hilbert_curve(step, parity, n - 1)       # Draw another with same parity
    right(90 * parity)     
    forward(step)
    hilbert_curve(step, -parity, n - 1)      # Draw smaller curve with flipped parity
    left(90 * parity)
    
# Set up the variables
n = 3
step = 500 / (2 ** n)  # scale step so curve stays within bounds

initializeTurtle()
showturtle()

# Set up the turtle
face(90)
jump(200, 550)
color('red')

# Draw the Hilbert Curve

hilbert_curve(step, 1, n)

show()

The plot below shows the result of interactively transforming a complex grid after one iteration, with the number of iterations controlled dynamically using the Manipulate interface. This built-in Wolfram Mathematica feature allows users to adjust parameters in real time and immediately observe the effects on the visual structure of the grid. The interface makes mexploration of complex behaviors both intuitive and efficient, enabling deeper insight into how iterative transformations distort mand evolve spatial patterns. Wolfram Mathematica is ideal for this task due to its native support for complex arithmetic, mefficient array operations, and built-in interactivity through Manipulate, making it easy to explore and share mathematical behavior visually and intuitively.

Hilbert Curves from n = 1 tp n = 6
Hilbert Curves: Variations from n = 1 to n = 6.

References

The following reference was consulted during the preparation of this lab:

  1. Wolfram, S. (2002). A new kind of science Wolfram Media.